/*
 * @Author: your name
 * @Date: 2021-12-08 15:08:46
 * @LastEditTime: 2022-03-24 17:28:45
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \starlight_cat_vue2\src\permission.js
 */
import router from './router'
import store from './store'
router.beforeEach((to, from, next) => {
  // setCache(to)
  next()
})

router.afterEach((to) => {
  setTags({
    ...to.meta,
    path: to.path
  }, to)
})

function setTags(tag = {}, to) {
  if (store.getters.tags.findIndex(({
      path
    }) => path == to.path) == -1)
    store.commit('app/SET_TAGS', [...store.getters.tags, tag])
}

// function setCache(to) {
//   to.meta.keepAlive = store.getters.tags.findIndex(({
//     path
//   }) => path == to.path) > -1;
// }